package com.flea.hclv.service.impl;

import com.flea.hclv.model.dao.HVisitorMapper;
import com.flea.hclv.model.dao.HVisitorOrderRelationMapper;
import com.flea.hclv.model.entity.HVisitor;
import com.flea.hclv.model.entity.HVisitorOrderRelation;
import com.flea.hclv.service.HVisitorOrderRelationService;
import com.flea.hclv.util.ServerResponse;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HVisitorOrderRelationServiceImpl implements HVisitorOrderRelationService {
  @Autowired
  private HVisitorOrderRelationMapper hVisitorOrderRelationMapper;
  @Autowired
  private HVisitorMapper hVisitorMapper;

  @Override
  public ServerResponse getVisitorsByOrderNo(String orderNo) {

    List<HVisitorOrderRelation> res = hVisitorOrderRelationMapper.findByOrderNo(orderNo);
    List<String> ids = new ArrayList<>();
    if(null!=res){
      for (HVisitorOrderRelation rel: res) {
          ids.add(rel.getVisitorId());
      }
      List<HVisitor> visitors =  hVisitorMapper.findByIds(ids);
      return ServerResponse.createBySuccess(visitors);
    }
    return ServerResponse.createByErrorMessage("未查到相关的游客");
  }
}
